package com.zzz.web.daoimpl;

import com.zzz.web.Data.XYaxis;
import com.zzz.web.dao.XYDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class XYDaoImpl implements XYDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void add(XYaxis xYaxis) {
        String sql = "insert into xy(x,y) values(?,?)";
        Object[] args = {xYaxis.getX(),xYaxis.getY()};
        jdbcTemplate.update(sql,args);
    }

    @Override
    public List<XYaxis> selectAll() {
        String sql = "select * from xy";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<XYaxis>(XYaxis.class));
    }

    @Override
    public void addTo2(XYaxis xYaxis) {
        String sql = "insert into xy2(x,y) values(?,?)";
        Object[] args = {xYaxis.getX(),xYaxis.getY()};
        jdbcTemplate.update(sql,args);
    }

    @Override
    public List<XYaxis> selectAllFrom2() {
        String sql = "select * from xy2";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<XYaxis>(XYaxis.class));
    }
}
